import configureStore from 'redux-mock-store'

import { createReducer, injectReducer } from 'reducers'
import { errorAlert } from 'modules/system'

const setup = () => {
  const mockStore = configureStore([])
  const store = mockStore({})

  store.asyncReducers = {}

  return {
    store,
  }
}

it('createReducer', () => {
  const reducers = createReducer([])

  expect(reducers).toMatchSnapshot()
  expect(reducers({}, errorAlert('error msg'))).toMatchSnapshot()
})

it('injectReducer', () => {
  const { store } = setup()
  const key = 'key'
  const reducer = jest.fn()

  injectReducer(store, { key, reducer })
  injectReducer(store, { key, reducer })

  expect(Object.keys(store.asyncReducers).length === 1).toBe(true)
  expect(store.asyncReducers).toMatchSnapshot()
})
